using NFreeMarker.Debug.Impl;

namespace NFreeMarker.Core
{
    /**
     * @author Attila Szegedi
     * @version $Id: DebugBreak.java,v 1.2 2004/09/11 13:11:14 stephanmueller Exp $
     */
    public class DebugBreak : TemplateElement
    {
        public DebugBreak(TemplateElement nestedBlock)
        {
            NestedBlock = nestedBlock;
            nestedBlock.Parent = this;
            CopyLocationFrom(nestedBlock);
        }

        internal override void Accept(Environment env)
        {
            if (!DebuggerService.SuspendEnvironment(env, NestedBlock.GetBeginLine()))
            {
                NestedBlock.Accept(env);
            }
            else
            {
                throw new StopException(env, "Stopped by debugger");        
            }
        }

        public override string GetDescription()
        {
            return NestedBlock.GetDescription();
        }

        public override string GetCanonicalForm()
        {
            return NestedBlock.GetCanonicalForm();
        }
    }
}